package com.example.win.android_banduyujia.http.request;

import android.os.Handler;
import android.os.Message;

import com.example.win.android_banduyujia.http.HttpUtils;
import com.example.win.android_banduyujia.http.UrlContext;
import com.example.win.android_banduyujia.http.response.BaseHttpResponse;
import com.example.win.android_banduyujia.http.response.ResponseError;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.CertActivity;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseActivity;

import org.json.JSONObject;

import java.util.Map;

/**
 * Created by Win on 2015/10/15.
 */
public class CerRequest extends BaseHttpRequest {
    public static final String URL = UrlContext.Url_UPLOAD.getContext();

    private String  mAccessToken = null;

    public CerRequest(String accessToken) {
        mAccessToken = accessToken;
    }

    public void doRequestFile(BaseActivity context,
                              Class<? extends  BaseHttpResponse> clzz,
                              boolean isShowProgressDialog, Handler pHandler, String file) {
           if(isShowProgressDialog){
               pHandler.sendEmptyMessage(AsycHttpRequest.CODE_TASK_START);
           }
        Message  message = new Message();
        JSONObject  result;
        BaseHttpResponse  response = null;
        ResponseError  error = new ResponseError();
        try{
            HttpUtils.uploadImage(toRequestURL(), getHttpHeader(), getHttpParams(), "avatar", "avatar", file);
            pHandler.sendEmptyMessage(AsycHttpRequest.CODE_TASK_END);
        }catch (Exception e){
            e.printStackTrace();
            error.setMessage("Client expection");
            pHandler.sendEmptyMessage(AsycHttpRequest.CODE_TASK_END);
        }
    }

    @Override
    protected String toRequestURL() {
        return  String.format(URL, mAccessToken);
    }

    @Override
    protected String toHttpMethod() {
        return HTTP_METHOD_POST;
    }

    @Override
    protected void toHttpRequestParams(Map<String, String> params) {
        params.put("file", "1");
    }
}
